﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Hue_Demo_Phone.ViewModels;

namespace Hue_Demo_Phone.Views
{
    public partial class HueClientView : PhoneApplicationPage
    {
        public HueClientView()
        {
            InitializeComponent();
            this.DataContext = App.HueClientVM;
        }

        void HueClientVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "IsUserRegistered" && _viewModel.IsUserRegistered == true)
            {
                startupUI.Visibility = Visibility.Collapsed;
            }
        }

        private HueClientViewModel _viewModel { get { return (HueClientViewModel)this.DataContext; } }

        private void StartLightCycle(object sender, System.EventArgs e)
        {
            _viewModel.StartCycle.Execute(null);
            
            // Basic Application Bar
            ApplicationBar = new ApplicationBar();

            ApplicationBarIconButton abib = new ApplicationBarIconButton();
            abib.Click += StopCycle;
            abib.IconUri = new Uri("/Toolkit.Content/ApplicationBar.Cancel.png", UriKind.Relative);
            abib.Text = "cycle";
            ApplicationBar.Buttons.Add(abib);            
        }

        private void StopCycle(object sender, System.EventArgs e)
        {
            _viewModel.EndCycle.Execute(null);

            // Basic Application Bar
            ApplicationBar = new ApplicationBar();

            ApplicationBarIconButton abib = new ApplicationBarIconButton();
            abib.Click += StopCycle;
            abib.IconUri = new Uri("/Assets/AppBar/sync.png", UriKind.Relative);
            abib.Text = "stop cycle";
            ApplicationBar.Buttons.Add(abib);            
        }

        private async void PlaySong(object sender, System.EventArgs e)
        {
            _viewModel.AnimateViewModel.SetCloseEncounters();
            ufo_tone.Play();
            _viewModel.AnimateViewModel.AnimateLights.Execute(null);

        }


    }
}